/************************************************************************/
// Copyright (C) 2016, han_gangbiao. All rights reserved.
// Use of this source code is governed by a GPL-v2 license that can be found in the License file.
// 
// [Time]:      2016-3-18 21:07:43
// [Author]:    han_gangbiao [http://my.oschina.net/jackhen]
// [Info]:      
/************************************************************************/

#ifndef INCLUDE_RPC_CLIENT_BASE_H_
#define INCLUDE_RPC_CLIENT_BASE_H_

#include "base/xrefptr.h"
#include "base/xmutex.h"
#include "base/xguard.h"
#include "base/xthread.h"
#include "net/net_reactor.h"
#include "protocol/net_binary_decoder.h"
#include "protocol/net_proto_def.h"

class CRpcClientMgr;
class CRpcClientBase : public smart::refobj_t
{
    friend class CRpcClientMgr;
public:
    CRpcClientBase( CRpcClientMgr* pMgr );
protected: //should not to delete
    virtual ~CRpcClientBase();

public:
    int start_rpc_client( const char* remote_ip, int remote_port );
    int stop_rpc_client();
    
public:
    int invoke( const smart::ref_ptr<NetBinaryPdu>& pdu );
protected:
    virtual int on_invoke( smart::ref_ptr<NetBinaryPdu> pdu ) = 0;
    virtual int on_rpc_close( int errcode ) = 0;

private:
    CRpcClientMgr* m_pMgr;
    SOCK_FD m_clifd;
    NetBinaryDecoder m_decoder;
};


#endif //~INCLUDE_RPC_CLIENT_BASE_H_

